home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / pascal / gpc1.1p2 / gpc1 / usr / src / gpc-1.1p2-2.6.3 / contrib / pie.p next >
Encoding:
Text File  |  1995-04-20  |  1.7 KB  |  99 lines

  1.  
  2. #include "xbgi.ph"
  3.  
  4. Program PieChart (Input,Output);
  5. { uses
  6.     graph,crt; }
  7.  
  8. import BgiGraphics;
  9.  
  10. const
  11.   maxinx = 10;
  12.  
  13. var
  14.   data : array [ 1..maxinx ] of record
  15.                   d : integer;    
  16.                   n : string(30);
  17.                 end;
  18.  
  19. function filldata : integer;
  20. begin
  21.   data[1].d := 55;  
  22.   data[2].d := 20;  
  23.   data[3].d := 10;  
  24.   data[4].d := 4;  
  25.   data[5].d := 3;  
  26.   data[6].d := 3;  
  27.   data[7].d := 2;  
  28.   data[8].d := 2;  
  29.   data[9].d := 2;  
  30.   data[10].d := 5;  
  31.  
  32.   data[1].n := 'Tekn. Yo.';  
  33.   data[2].n := 'Yo';  
  34.   data[3].n := 'Ins';  
  35.   data[4].n := 'Asent';  
  36.   data[5].n := 'Fil. Yo.';  
  37.   data[6].n := 'Kaupt.Yo';  
  38.   data[7].n := 'Valt.Yo.';  
  39.   data[8].n := 'Arkkit.Yo';  
  40.   data[9].n := 'Ei mitaan';  
  41.   data[10].n := 'Muut';  
  42.  
  43.   filldata := maxinx;
  44. end;
  45.  
  46. type
  47.   stype = packed array [ 1..255 ] of char;
  48.  
  49. var
  50.   Driver : integer;
  51.   mode   : integer;
  52.   foo    : stype;
  53.   cptr   : ^char;
  54.  
  55. var
  56.   total : real value 0.0;
  57.   y,x,r : integer value 0;
  58.   i,lkm : integer;
  59.   j     : real value 0.0;
  60.   ch    : char;
  61.  
  62. Begin
  63.   detectgraph(driver,mode);
  64.  
  65.   lkm := filldata;
  66.   for i := 1 to lkm do
  67.     total := total + data[i].d;
  68.  
  69.   initgraph(driver,mode,foo);
  70.   y := trunc(getmaxy/2);
  71.   x := y;
  72.   r := y;
  73.  
  74.   settextstyle (0, 0, 4);
  75.  
  76.   for i := 1 to lkm do
  77.   begin
  78.    setlinestyle (0, 0, 3);
  79.    setfillstyle(1,i);
  80.    pieslice(trunc(x+x/10),
  81.         y,
  82.             trunc(j), 
  83.         trunc(j+(data[i].d*360)/total),
  84.         r);
  85.    j := j + ((data[i].d*360)/total);
  86.    bar3d(trunc(x*2+3*x/10),
  87.      trunc(r*2/lkm*(i-1)),
  88.      trunc(x*2+4*x/10),
  89.      trunc(r*2/lkm*i),
  90.      0,
  91.      0);
  92.  
  93.   writestr (foo, data[i].n,' ',trunc((data[i].d*100)/total):2);
  94.   outtextxy(trunc(2*x+5*x/10+5),trunc(r*2/lkm*(i-1)+3),foo);
  95.   end;
  96.   read(ch);
  97.   closegraph;
  98. end.
  99.